package ge.telasi.tasks.ui.comp;

import ge.telasi.tasks.ui.UIUtils;
import ge.telasi.tasks.ui.log.Logger;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.KeyStroke;

/**
 * @author dimitri
 */
public abstract class CommonDialog extends JDialog {
    private Logger logger;

    public CommonDialog(Component parent, boolean modal) {
        super(UIUtils.findShell(parent), modal ? ModalityType.APPLICATION_MODAL : ModalityType.MODELESS);
        KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
        ActionListener action = new ActionListener() {
            public void actionPerformed(ActionEvent actionEvent) {
                dispose();
            }
        };
        getRootPane().registerKeyboardAction(action, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);
    }

    public Logger getLogger() {
        return logger;
    }

    public void setLogger(Logger logger) {
        this.logger = logger;
    }

}
